package com.jinzecloud.fiction.controller;

//import com.baomidou.mybatisplus.core.toolkit.IOUtils;
import com.jinzecloud.fiction.bean.TbAdmin;
import com.jinzecloud.fiction.service.TbAdminService;
import com.jinzecloud.fiction.utils.R;
import com.jinzecloud.fiction.vo.TbAdminVo;
import com.jinzecloud.fiction.vo.TbAdminVos;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.google.code.kaptcha.Producer;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/fiction")
public class LoginController {

    @Autowired
    TbAdminService tbAdminService;
    @Autowired
    HttpServletRequest request;

    @GetMapping("/captchaJpg")
    public void captcha(HttpServletRequest request,HttpServletResponse response,String uuid) throws Exception {
        tbAdminService.getCode(request,response,uuid);
    }

    @PostMapping("/login")
    public R login(@RequestBody TbAdminVos tbAdminVos) throws Exception{
        R r = tbAdminService.getByUsernameAndPassword(tbAdminVos);
        return r;
    }
    @GetMapping("/Logout")
    public R Logout(@RequestParam("token") String token) {
        R r = tbAdminService.Logout(token);
        return r;
    }

}
